package com.ziq.zcamp.util;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;


/***
 * @author: YangLang
 * @version: v1.0
 */
public class ClipBoardUtil {

    /**
     * 清除剪切板内容
     */
    public static void cleanClipBoard(Context context) {
        addToClipboard(context,"");
    }

    /**
     * 将字符串添加到剪贴板
     */
    public static void addToClipboard(Context context, String msg) {
        if (AndroidVersion.AT_LEASET_11) {// API版本大于等于11 也就是3.0才能使用新方式
            ClipData clip = ClipData.newPlainText("simple text", msg);
            // https://bugly.qq.com/v2/crash-reporting/crashes/900012289/12592299/report?pid=1&crashDataType=undefined&start=0
            try {
                ((ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(clip);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            ((ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE)).setText(msg);
        }
    }
}
